package saucaca.JSON;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import saucaca.Object.AccountObject;
import saucaca.Object.AlbumObject;
import saucaca.Object.AreaObject;
import saucaca.Object.CommentObject;
import saucaca.Object.HeaderObject;
import saucaca.Object.HomeData;
import saucaca.Object.MenuObject;
import saucaca.Object.NewsObject;
import saucaca.Object.PlaylistObject;
import saucaca.Object.RingtoneObject;
import saucaca.Object.SingerObject;
import saucaca.Object.SlideObject;
import saucaca.Object.SongObject;
import saucaca.Object.TelcoObject;
import saucaca.Object.TopicObject;
import saucaca.Object.TvshowObject;
import saucaca.Util.TagName;

public class JsonReader {
	String TAG = "JsonReader";

	private static String TOKEN;
	private static String KEY;

	public static void readHeader(String json) throws JSONException {
		JSONObject jObj2 = new JSONObject(json).getJSONObject("Header");
		if(HomeData.headerObject==null)
			HomeData.headerObject = new HeaderObject();
		String code = (String) jObj2.get("Code");
		String message = (String) jObj2.get("Message");
		String cmd = (String) jObj2.get(TagName.CMD);
		HomeData.headerObject.setCODE(code);
		HomeData.headerObject.setMESSAGE(message);
		HomeData.headerObject.setCMD(cmd);
//		 Log.e("TAG", "HeaderObject:" + "getCODE: " +
//		 HomeData.headerObject.getCODE());
//		 Log.e("TAG", "HeaderObject:" + "getMESSAGE: " +
//		 HomeData.headerObject.getMESSAGE());
//		 Log.e("TAG", "HeaderObject:" + "getCMD: " +
//		 HomeData.headerObject.getCMD());
	}

	private static JSONObject readBodydata(String json) throws JSONException {
		// readHeader(json);
		JSONObject jObj = new JSONObject(json).getJSONObject(TagName.BODY);
		String json1 = (String) jObj.get(TagName.DATA);
		JSONObject jsonObject = new JSONObject(json1);
		return jsonObject;
	}

	private static void readTokenKey(String json) throws JSONException {
		JSONObject jObj2 = new JSONObject(json).getJSONObject(TagName.FOOTER);
		TOKEN = (String) jObj2.get(TagName.TOKEN);
		KEY = (String) jObj2.get(TagName.KEY);
	}

	// HOME_________________________________________________________________
	public static void readHomeData(String json) throws JSONException {
		JSONObject jObjData = readBodydata(json);
		JSONArray jsonArrayMenu = jObjData.getJSONArray(TagName.KEY_MENU);
		JSONArray jsonArrayVideoHot = jObjData.getJSONArray(TagName.KEY_VIDEO_TOP);
		JSONArray jsonArrayBXHSong = jObjData.getJSONArray("BXH");
		JSONArray jsonArrayBXHVideo = jObjData.getJSONArray("BXH_VIDEO");
		JSONArray jsonArrayBXHAlbum = jObjData.getJSONArray("BXH_ALBUM");
		JSONArray jsonArraySong = jObjData.getJSONArray(TagName.KEY_SONG);
		JSONArray jsonArrayAlbum = jObjData.getJSONArray(TagName.KEY_ALBUM);
		JSONArray jsonArrayNews = jObjData.getJSONArray(TagName.KEY_NEWS);
		JSONArray jsonArrayTopics = jObjData.getJSONArray(TagName.KEY_TOPIC);
		JSONArray jsonArrayCate = jObjData.getJSONArray("CATE");
		JSONArray jsonArrayArea = jObjData.getJSONArray("AREA");
		JSONArray jsonArrayRingtone = jObjData.getJSONArray("TONE");
		JSONArray jsonArrayTelco = jObjData.getJSONArray("TELCO");
		JSONArray jsonArraySlide = jObjData.getJSONArray("SLIDE");

		HomeData.homeListMENU = readlistMenu(jsonArrayMenu);
		HomeData.homeListSlide = readlistSlide(jsonArraySlide);
		HomeData.homeListVideoHOT = readlistSongs(jsonArrayVideoHot);
		HomeData.homeListBXHSong = readlistSongs(jsonArrayBXHSong);
		HomeData.homeListBXHVideo = readlistSongs(jsonArrayBXHVideo);
		HomeData.homeListBXHAlbum = readlistAlbums(jsonArrayBXHAlbum);
		HomeData.homeListSong = readlistSongs(jsonArraySong);
		HomeData.homeListAlbum = readlistAlbums(jsonArrayAlbum);
		HomeData.homeListNews = readlistNews(jsonArrayNews);
		HomeData.homeListTopics = readlistTopics(jsonArrayTopics);
		HomeData.homeListCate = readlistTopics(jsonArrayCate);
		HomeData.homeListArea = readlistArea(jsonArrayArea);
		HomeData.homeListRingtone = readlistRingtone(jsonArrayRingtone);
		HomeData.homeListTelco = readlistTelco(jsonArrayTelco);
		readTokenKey(json);
	}

	public static String getToken() {
		return TOKEN;
	}

	public static String getKey() {
		return KEY;
	}
	
	private static ArrayList<SongObject> readlistSongs(JSONArray jsonArrayMenu) throws JSONException {
		ArrayList<SongObject> listSongs = new ArrayList<SongObject>();
		for (int i = 0; i < jsonArrayMenu.length(); i++) {
			JSONObject menuObj = jsonArrayMenu.getJSONObject(i);
			SongObject song = new SongObject();
			if(!menuObj.isNull(TagName.SONG_ID))
				song.setSONG_ID(menuObj.getString(TagName.SONG_ID));
			if(!menuObj.isNull(TagName.TXNAME))
				song.setTXNAME(menuObj.getString(TagName.TXNAME));
			if(!menuObj.isNull(TagName.SONG_CODE))
				song.setSONG_CODE(menuObj.getString(TagName.SONG_CODE));
			if(!menuObj.isNull(TagName.AVATAR))
				song.setAVATAR(menuObj.getString(TagName.AVATAR));
			if(!menuObj.isNull(TagName.NAME_SINGERS))
				song.setNAME_SINGERS(menuObj.getString(TagName.NAME_SINGERS));
			if(!menuObj.isNull(TagName.ID_SINGERS))
				song.setID_SINGERS(menuObj.getString(TagName.ID_SINGERS));
			if(!menuObj.isNull(TagName.ISVIEW))
				song.setISVIEW(menuObj.getString(TagName.ISVIEW));
			if(!menuObj.isNull(TagName.ISDOWN))
				song.setISDOWN(menuObj.getString(TagName.ISDOWN));
			if(!menuObj.isNull(TagName.RN))
				song.setRN(menuObj.getString(TagName.RN));
			if(!menuObj.isNull(TagName.PATCH_FULL))
				song.setPATCH_FULL(menuObj.getString(TagName.PATCH_FULL));
			if(!menuObj.isNull(TagName.LYRCIS))
				song.setLYRCIS(menuObj.getString(TagName.LYRCIS));
			if(!menuObj.isNull(TagName.SHORTDESC))
				song.setSHORTDESC(menuObj.getString(TagName.SHORTDESC));
			if(!menuObj.isNull(TagName.TYPE_VIDEO))
				song.setTYPE_VIDEO(menuObj.getString(TagName.TYPE_VIDEO));
			if(!menuObj.isNull(TagName.ISTONE))
				song.setISTONE(menuObj.getString(TagName.ISTONE));
			if(!menuObj.isNull(TagName.SEO_NAME))
				song.setSEO_NAME(menuObj.getString(TagName.SEO_NAME));
			if(!menuObj.isNull(TagName.TXURL))
				song.setTXURL(menuObj.getString(TagName.TXURL));
			song.setFormNet(true);
//			song.showSonginfo();
			listSongs.add(song);
		}
		return listSongs;
	}
	

	private static ArrayList<AlbumObject> readListAlbums(JSONArray jsonArrayMenu) throws JSONException {
		ArrayList<AlbumObject> listVideo = new ArrayList<AlbumObject>();
		for (int i = 0; i < jsonArrayMenu.length(); i++) {
			AlbumObject videoObj = new AlbumObject();
			JSONObject videoJson = jsonArrayMenu.getJSONObject(i);
			if(!videoJson.isNull(TagName.ALBUM_ID))
				videoObj.setALBUM_ID(videoJson.getString(TagName.ALBUM_ID));
			if(!videoJson.isNull(TagName.TXNAME))
				videoObj.setTXNAME(videoJson.getString(TagName.TXNAME));
			if(!videoJson.isNull(TagName.SEO_NAME))
				videoObj.setSEO_NAME(videoJson.getString(TagName.SEO_NAME));
			if(!videoJson.isNull(TagName.CREATE_DATE))
				videoObj.setCREATE_DATE(videoJson.getString(TagName.CREATE_DATE));
			if(!videoJson.isNull(TagName.SHORTDESC))
				videoObj.setSHORTDESC(videoJson.getString(TagName.SHORTDESC));
			if(!videoJson.isNull(TagName.NAME_SINGERS))
				videoObj.setNAME_SINGERS(videoJson.getString(TagName.NAME_SINGERS));
			if(!videoJson.isNull(TagName.AVATAR))
				videoObj.setAVATAR(videoJson.getString(TagName.AVATAR));
			if(!videoJson.isNull(TagName.ISVIEW))
				videoObj.setISVIEW(videoJson.getString(TagName.ISVIEW));
			if(!videoJson.isNull(TagName.RN))
				videoObj.setRN(videoJson.getString(TagName.RN));
			listVideo.add(videoObj);
		}
//		for (int i = 0; i < listVideo.size(); i++) {
//			TagName.showLogError("Readlistalbum", "____________________________________");
//			listVideo.get(i).showinfo();
//		}
		return listVideo;
	}
	private static ArrayList<MenuObject> readlistMenu(JSONArray jsonArrayMenu) throws JSONException {
		ArrayList<MenuObject> listmenu = new ArrayList<MenuObject>();
		MenuObject menu;
		for (int i = 0; i < jsonArrayMenu.length(); i++) {
			menu = new MenuObject();
			JSONObject menuObj = jsonArrayMenu.getJSONObject(i);
			menu.setName(menuObj.getString(TagName.TXNAME));
			menu.setMenuCode(menuObj.getString(TagName.MENU_CODE));
			menu.setSubMenuType(menuObj.getString(TagName.SUBMENU_TYPE));
			menu.setKeycate(menuObj.getString(TagName.KEY_CATE));
			menu.setParentCode(menuObj.getString(TagName.PARENT_CODE));
			menu.setAvatar(menuObj.getString(TagName.AVATAR));
			menu.setRn(menuObj.getString(TagName.RN));
			listmenu.add(menu);
		}
		return listmenu;
	}
	
	private static ArrayList<SlideObject> readlistSlide(JSONArray jsonArrayMenu) throws JSONException {
		ArrayList<SlideObject> listmenu = new ArrayList<SlideObject>();
		SlideObject menu;
		for (int i = 0; i < jsonArrayMenu.length(); i++) {
			menu = new SlideObject();
			JSONObject menuObj = jsonArrayMenu.getJSONObject(i);
			menu.setTXTNAME(menuObj.getString(TagName.TXNAME));
			menu.setAVATAR(menuObj.getString(TagName.AVATAR));
			menu.setSHORTDESC(menuObj.getString(TagName.SHORTDESC));
			menu.setTXURL(menuObj.getString(TagName.TXURL));
			menu.setOBJECT_ID(menuObj.getString("OBJECT_ID"));
			menu.setOTYPE(menuObj.getString("OTYPE"));
			menu.setRN(menuObj.getString(TagName.RN));
			menu.showinfo();
			listmenu.add(menu);
		}
		return listmenu;
	}
	private static ArrayList<RingtoneObject> readlistRingtone(JSONArray jsonArrayArea) throws JSONException {
		ArrayList<RingtoneObject> listVideo = new ArrayList<RingtoneObject>();
		RingtoneObject videoObj;
		for (int i = 0; i < jsonArrayArea.length(); i++) {
			videoObj = new RingtoneObject();
			JSONObject videoJson = jsonArrayArea.getJSONObject(i);
			videoObj.setTXNAME(videoJson.getString(TagName.TXNAME));
			videoObj.setSEO_NAME(videoJson.getString(TagName.SEO_NAME));
			videoObj.setSONG_ID(videoJson.getString(TagName.SONG_ID));
			videoObj.setTELCO(videoJson.getString(TagName.TELCO));
			videoObj.setTELCO_ID(videoJson.getString(TagName.TELCO_ID));
			listVideo.add(videoObj);
		}
		return listVideo;
	}

	private static ArrayList<AreaObject> readlistArea(JSONArray jsonArrayArea) throws JSONException {
		ArrayList<AreaObject> listVideo = new ArrayList<AreaObject>();
		AreaObject videoObj;
		for (int i = 0; i < jsonArrayArea.length(); i++) {
			videoObj = new AreaObject();
			JSONObject videoJson = jsonArrayArea.getJSONObject(i);
			videoObj.setAREA_CODE(videoJson.getString("AREA_CODE"));
			videoObj.setTXNAME(videoJson.getString(TagName.TXNAME));
//			TagName.showLogError("AREA", "AREA_CODE: "+videoObj.getAREA_CODE());
//			TagName.showLogError("AREA", "AREA_NAME: "+videoObj.getTXNAME());
			listVideo.add(videoObj);
		}
		return listVideo;
	}

	private static ArrayList<TelcoObject> readlistTelco(JSONArray jsonArrayArea) throws JSONException {
		ArrayList<TelcoObject> listVideo = new ArrayList<TelcoObject>();
		TelcoObject videoObj;
		for (int i = 0; i < jsonArrayArea.length(); i++) {
			videoObj = new TelcoObject();
			JSONObject videoJson = jsonArrayArea.getJSONObject(i);
			videoObj.setTXNAME(videoJson.getString(TagName.TXNAME));
			videoObj.setTELCO_ID(videoJson.getString("TELCO_ID"));
			videoObj.setCODE(videoJson.getString(TagName.KEY_CODE));
			videoObj.setSYNTAX(videoJson.getString("SYNTAX"));
			videoObj.setSEND_GIFTS(videoJson.getString("SEND_GIFTS"));
			videoObj.setSHORT_CODE(videoJson.getString("SHORT_CODE"));
//			videoObj.showinfo();
			listVideo.add(videoObj);
		}
		return listVideo;
	}

	private static ArrayList<AlbumObject> readlistAlbums(JSONArray jsonArrayMenu) throws JSONException {
		return readListAlbums(jsonArrayMenu);
	}



	// home tintuc
	private static ArrayList<NewsObject> readlistNews(JSONArray jsonArrayNew) throws JSONException {
		ArrayList<NewsObject> listmenu = new ArrayList<NewsObject>();
		for (int i = 0; i < jsonArrayNew.length(); i++) {
			NewsObject news = new NewsObject();
			JSONObject menuObj = jsonArrayNew.getJSONObject(i);
			news.setAUTO_ID(menuObj.getString(TagName.AUTO_ID));
			news.setTXNAME(menuObj.getString(TagName.TXNAME));
			news.setSEO_NAME(menuObj.getString(TagName.SEO_NAME));
			news.setCATE_CODE(menuObj.getString(TagName.CATE_CODE));
			news.setCATE_NAME(menuObj.getString(TagName.CATE_NAME));
			news.setSHORT_DESC(menuObj.getString(TagName.SHORT_DESC));
			news.setLAST_DATE(menuObj.getString(TagName.LAST_DATE));
			news.setISVIEW(menuObj.getString(TagName.ISVIEW));
			news.setAVATAR(menuObj.getString(TagName.AVATAR));
			news.setRN(menuObj.getString(TagName.RN));
			listmenu.add(news);
		}
		return listmenu;
	}

	public static NewsObject readNewsDetail(String json) throws JSONException {
		JSONObject jObjData = readBodydata(json);
		JSONArray jsonArrayNew = jObjData.getJSONArray(TagName.KEY_NEW);
		NewsObject news = new NewsObject();
		JSONObject menuObj = jsonArrayNew.getJSONObject(0);
		news.setAUTO_ID(menuObj.getString(TagName.AUTO_ID));
		news.setTXNAME(menuObj.getString(TagName.TXNAME));
		news.setSHORT_DESC(menuObj.getString(TagName.SHORT_DESC));
		news.setSEO_NAME(menuObj.getString(TagName.SEO_NAME));
		news.setCONTENTS(menuObj.getString(TagName.CONTENTS));
		news.setAVATAR(menuObj.getString(TagName.AVATAR));
		news.setCATE_CODE(menuObj.getString(TagName.CATE_CODE));
		news.setCATE_NAME(menuObj.getString(TagName.CATE_NAME));
		news.setLAST_DATE(menuObj.getString(TagName.LAST_DATE));
		news.setISVIEW(menuObj.getString(TagName.ISVIEW));
		return news;
	}

	public static ArrayList<NewsObject> readNewsDetail_List(String json) throws JSONException {
		JSONObject jObjData = readBodydata(json);
		JSONArray jsonArrayNew = jObjData.getJSONArray(TagName.KEY_LISTNEW);
		ArrayList<NewsObject> listmenu = new ArrayList<NewsObject>();
		for (int i = 0; i < jsonArrayNew.length(); i++) {
			NewsObject news = new NewsObject();
			JSONObject menuObj = jsonArrayNew.getJSONObject(i);
			news.setAUTO_ID(menuObj.getString(TagName.AUTO_ID));
			news.setSEO_NAME(menuObj.getString(TagName.SEO_NAME));
			news.setTXNAME(menuObj.getString(TagName.TXNAME));
			news.setSHORT_DESC(menuObj.getString(TagName.SHORT_DESC));
			news.setAVATAR(menuObj.getString(TagName.AVATAR));
			news.setLAST_DATE(menuObj.getString(TagName.LAST_DATE));
			news.setRN(menuObj.getString(TagName.RN));

			// news.setAUTO_ID(menuObj.getString(TagName.AUTO_ID));
			// news.setSEO_NAME(menuObj.getString(TagName.SEO_NAME));
			// news.setTXNAME(menuObj.getString(TagName.TXNAME));
			// news.setSHORT_DESC(menuObj.getString(TagName.SHORT_DESC));
			// news.setAVATAR(menuObj.getString(TagName.AVATAR));
			// news.setLAST_DATE(menuObj.getString(TagName.LAST_DATE));
			//
			// news.setCATE_CODE(menuObj.getString(TagName.CATE_CODE));
			// news.setCATE_NAME(menuObj.getString(TagName.CATE_NAME));
			// news.setCONTENTS(menuObj.getString(TagName.CONTENTS));
			// news.setISVIEW(menuObj.getString(TagName.ISVIEW));
			listmenu.add(news);
		}
		return listmenu;
	}

	public static ArrayList<NewsObject> readNews_List(String json) throws JSONException {
		JSONObject jObjData = readBodydata(json);
		JSONArray jsonArrayNew = jObjData.getJSONArray(TagName.KEY_NEW);
		ArrayList<NewsObject> listmenu = new ArrayList<NewsObject>();
		for (int i = 0; i < jsonArrayNew.length(); i++) {
			NewsObject news = new NewsObject();
			JSONObject menuObj = jsonArrayNew.getJSONObject(i);
			news.setAUTO_ID(menuObj.getString(TagName.AUTO_ID));
			news.setSEO_NAME(menuObj.getString(TagName.SEO_NAME));
			news.setTXNAME(menuObj.getString(TagName.TXNAME));
			news.setSHORT_DESC(menuObj.getString(TagName.SHORT_DESC));
			news.setAVATAR(menuObj.getString(TagName.AVATAR));
			news.setCATE_CODE(menuObj.getString(TagName.CATE_CODE));
			news.setCATE_NAME(menuObj.getString(TagName.CATE_NAME));
			news.setLAST_DATE(menuObj.getString(TagName.LAST_DATE));
			news.setRN(menuObj.getString(TagName.RN));
			news.setISVIEW(menuObj.getString(TagName.ISVIEW));

			// news.setAUTO_ID(menuObj.getString(TagName.AUTO_ID));
			// news.setSEO_NAME(menuObj.getString(TagName.SEO_NAME));
			// news.setTXNAME(menuObj.getString(TagName.TXNAME));
			// news.setSHORT_DESC(menuObj.getString(TagName.SHORT_DESC));
			// news.setAVATAR(menuObj.getString(TagName.AVATAR));
			// news.setLAST_DATE(menuObj.getString(TagName.LAST_DATE));
			//
			// news.setCONTENTS(menuObj.getString(TagName.CONTENTS));
			listmenu.add(news);
		}
		return listmenu;
	}

	// home Topic
	private static ArrayList<TopicObject> readlistTopics(JSONArray jsonArrayNew) throws JSONException {
		ArrayList<TopicObject> listmenu = new ArrayList<TopicObject>();
		for (int i = 0; i < jsonArrayNew.length(); i++) {
			TopicObject topic = new TopicObject();
			JSONObject menuObj = jsonArrayNew.getJSONObject(i);
			if(!menuObj.isNull(TagName.CATE_CODE))
			topic.setCATE_CODE(menuObj.getString(TagName.CATE_CODE));
			if(!menuObj.isNull(TagName.TXNAME))
			topic.setTXNAME(menuObj.getString(TagName.TXNAME));
			if(!menuObj.isNull(TagName.MOD_CODE))
			topic.setMOD_CODE(menuObj.getString(TagName.MOD_CODE));
			if(!menuObj.isNull(TagName.AVATAR))
			topic.setAVATAR(menuObj.getString(TagName.AVATAR));
			if(!menuObj.isNull(TagName.IS_BTYPE))
			topic.setIS_BTYPE(menuObj.getString(TagName.IS_BTYPE));
			if(!menuObj.isNull(TagName.RN))
			topic.setRN(menuObj.getString(TagName.RN));
			listmenu.add(topic);
		}
//		for (int i = 0; i < listmenu.size(); i++) {
//			Log.e("ListTopics", "___________________________________");
//			listmenu.get(i).showinfo();
//		}
		return listmenu;
	}

	// Login
	public static void loginReader(String json) throws JSONException {
		readHeader(json);
		// read BODY
		JSONObject jObjData = readBodydata(json);
		JSONArray jsonArrayUser = jObjData.getJSONArray(TagName.USER);
		ArrayList<AccountObject> listAccount = new ArrayList<AccountObject>();
		AccountObject aObject;
		for (int i = 0; i < jsonArrayUser.length(); i++) {
			aObject = new AccountObject();
			JSONObject accObj = jsonArrayUser.getJSONObject(0);
			aObject.setFULL_NAME(accObj.getString(TagName.FULL_NAME));
			aObject.setUSER_CODE(accObj.getString(TagName.USER_CODE));
			aObject.setUSER_NAME(accObj.getString(TagName.USER_NAME));
			aObject.setSEX(accObj.getString(TagName.SEX));
			aObject.setBIRTH_DAY(accObj.getString(TagName.BIRTH_DAY));
			aObject.setAVATAR(accObj.getString(TagName.AVATAR));
			aObject.setMOBILE(accObj.getString(TagName.MOBILE));
			listAccount.add(aObject);
		}
		readTokenKey(json);
		HomeData.homeAccount = listAccount.get(0);
	}

	// Video
	public static List<SongObject> getVideosongReader(String json) throws JSONException {
		JSONObject jObjData = readBodydata(json);
		JSONArray jsonArraySong = jObjData.getJSONArray(TagName.KEY_SONG);
		readTokenKey(json);
		return readlistSongs(jsonArraySong);
	}

	// Album
	public static List<AlbumObject> readAlbumDetails(String json) throws JSONException {
		JSONObject jObjData = readBodydata(json);
		JSONArray jsonArrayAlbumhot = jObjData.getJSONArray(TagName.KEY_ALBUM);
		
		return readListAlbums(jsonArrayAlbumhot);
	}
	
	public static List<AlbumObject> getAlbumHot(String json) throws JSONException {
		JSONObject jObjData = readBodydata(json);
		JSONArray jsonArrayAlbumhot = jObjData.getJSONArray(TagName.ALBUM_HOT);
		
		return readListAlbums(jsonArrayAlbumhot);
	}

	public static List<AlbumObject> getAlbumNew(String json) throws JSONException {
		JSONObject jObjData = readBodydata(json);
		JSONArray jsonArrayAlbumNew = jObjData.getJSONArray(TagName.ALBUM_NEW);
		
		return readListAlbums(jsonArrayAlbumNew);
	}

	//
	public static List<AlbumObject> getAlbumView(String json) throws JSONException {
		JSONObject jObjData = readBodydata(json);
		JSONArray jsonArrayAlbumView = jObjData.getJSONArray(TagName.ALBUM_VIEW);
		return  readListAlbums(jsonArrayAlbumView);
	}

	public static List<SingerObject> getArtistReader(String json) throws JSONException {
		JSONObject jObjData = readBodydata(json);
		JSONArray jsonArraySong = jObjData.getJSONArray(TagName.KEY_SINGER);
		ArrayList<SingerObject> listSinger = new ArrayList<SingerObject>();

		for (int i = 0; i < jsonArraySong.length(); i++) {
			SingerObject singer = new SingerObject();
			JSONObject menuObj = jsonArraySong.getJSONObject(i);
			singer.setSINGER_ID(menuObj.getString(TagName.SINGER_ID));
			singer.setSINGER_CODE(menuObj.getString(TagName.SINGER_CODE));
			singer.setTXNAME(menuObj.getString(TagName.TXNAME));
			singer.setAVATAR(menuObj.getString(TagName.AVATAR));
			singer.setRN(menuObj.getString(TagName.RN));
			listSinger.add(singer);
		}
		readTokenKey(json);
		return listSinger;
	}

	public static List<SingerObject> getArtistDetai(String json) throws JSONException {
		JSONObject jObjData = readBodydata(json);
		JSONArray jsonArraySong = jObjData.getJSONArray(TagName.KEY_SINGER);
		ArrayList<SingerObject> listSinger = new ArrayList<SingerObject>();

		for (int i = 0; i < jsonArraySong.length(); i++) {
			SingerObject singer = new SingerObject();
			JSONObject menuObj = jsonArraySong.getJSONObject(i);
			singer.setSINGER_ID(menuObj.getString(TagName.SINGER_ID));
			singer.setSINGER_CODE(menuObj.getString(TagName.SINGER_CODE));
			singer.setTXNAME(menuObj.getString(TagName.TXNAME));
			singer.setSHORTDESC(menuObj.getString(TagName.SHORTDESC));
			singer.setAVATAR(menuObj.getString(TagName.AVATAR));
			singer.setBIRTHDAY(menuObj.getString(TagName.BIRTHDAY));
			singer.setSEX(menuObj.getString(TagName.SEX));
			listSinger.add(singer);
		}
		readTokenKey(json);
		return listSinger;
	}

	public static ArrayList<SongObject> readlistSongFromString(String json, String Key) throws JSONException {
		JSONObject jObjData = readBodydata(json);
		JSONArray jsonArraySong = jObjData.getJSONArray(Key);
		return readlistSongs(jsonArraySong);
	}

	public static ArrayList<SongObject> readlistSongArtist(String json) throws JSONException {
		JSONObject jObjData = readBodydata(json);
		JSONArray jsonArraySong = jObjData.getJSONArray(TagName.KEY_SONG);
		return readlistSongs(jsonArraySong);
	}

	public static ArrayList<SongObject> readlistVideo(String json) throws JSONException {
		JSONObject jObjData = readBodydata(json);
		JSONArray jsonArraySong = jObjData.getJSONArray(TagName.KEY_SONG);
		return readlistSongs(jsonArraySong);
	}

	public static ArrayList<AlbumObject> readlistAlbumFromString(String json, String Key) throws JSONException {
		JSONObject jObjData = readBodydata(json);
		JSONArray jsonArraySong = jObjData.getJSONArray(Key);
		return  readListAlbums(jsonArraySong);
	}

	public static ArrayList<AlbumObject> artistAlbum(String json) throws JSONException {
		JSONObject jObjData = readBodydata(json);
		JSONArray jsonArraySong = jObjData.getJSONArray(TagName.KEY_ALBUM);
		return  readListAlbums(jsonArraySong);
	}


	public static ArrayList<SongObject> readSongdetail(String json) throws JSONException {
		JSONObject jObjData = readBodydata(json);
		JSONArray jsonArraySong = jObjData.getJSONArray(TagName.KEY_SONG);
		return readlistSongs(jsonArraySong);
	}
	public static ArrayList<SongObject> readListsong(String json) throws JSONException {
		JSONObject jObjData = readBodydata(json);
		JSONArray jsonArraySong = jObjData.getJSONArray("LISTSONG");
		return readlistSongs(jsonArraySong);
	}
	public static AlbumObject readAlbumdetail(String json) throws JSONException {
		JSONObject jObjData = readBodydata(json);
		JSONArray jsonArraySong = jObjData.getJSONArray(TagName.KEY_ALBUM);
		return  readListAlbums(jsonArraySong).get(0);
	}

	public static ArrayList<SongObject> readAlbum_listSong(String json) throws JSONException {
		JSONObject jObjData = readBodydata(json);
		JSONArray jsonArraySong = jObjData.getJSONArray(TagName.KEY_SONG);
		return readlistSongs(jsonArraySong);
	}

	public static ArrayList<RingtoneObject> readRingToneDetails(String json) throws JSONException {
		JSONObject jObjData = readBodydata(json);
		JSONArray jsonArraySong = jObjData.getJSONArray(TagName.KEY_TONE);
		ArrayList<RingtoneObject> listmenu = new ArrayList<RingtoneObject>();
		for (int i = 0; i < jsonArraySong.length(); i++) {
			RingtoneObject song = new RingtoneObject();
			JSONObject songObj = jsonArraySong.getJSONObject(i);
			song.setSONG_ID(songObj.getString(TagName.SONG_ID));
			song.setTXNAME(songObj.getString(TagName.TXNAME));
			song.setPATCH_DEMO(songObj.getString(TagName.PATCH_DEMO));
			song.setISDOWN(songObj.getString(TagName.ISDOWN));
			song.setNAME_SINGERS(songObj.getString(TagName.NAME_SINGERS));
			song.setID_SINGERS(songObj.getString(TagName.ID_SINGERS));
			song.setGPC_SYNTAX(songObj.getString(TagName.GPC_SYNTAX));
			song.setVMS_SYNTAX(songObj.getString(TagName.VMS_SYNTAX));
			song.setVTL_SYNTAX(songObj.getString(TagName.VTL_SYNTAX));
			song.setVNM_SYNTAX(songObj.getString(TagName.VNM_SYNTAX));
			listmenu.add(song);
		}
		return listmenu;
	}
	public static ArrayList<RingtoneObject> readList_ringtone(String json) throws JSONException {
		JSONObject jObjData = readBodydata(json);
		JSONArray jsonArraySong = jObjData.getJSONArray(TagName.KEY_TONE);
		ArrayList<RingtoneObject> listVideo = new ArrayList<RingtoneObject>();
		for (int i = 0; i < jsonArraySong.length(); i++) {
			RingtoneObject videoObj = new RingtoneObject();
			JSONObject videoJson = jsonArraySong.getJSONObject(i);
			videoObj.setSONG_ID(videoJson.getString(TagName.SONG_ID));
			videoObj.setTXNAME(videoJson.getString(TagName.TXNAME));
			videoObj.setSONG_CODE(videoJson.getString(TagName.SONG_CODE));
			videoObj.setNAME_SINGERS(videoJson.getString(TagName.NAME_SINGERS));
			videoObj.setID_SINGERS(videoJson.getString(TagName.ID_SINGERS));
			listVideo.add(videoObj);
		}
		return listVideo;
	}

	public static ArrayList<TvshowObject> readTvshow(String json) throws JSONException {
		JSONObject jObjData = readBodydata(json);
		JSONArray jsonArraySong = jObjData.getJSONArray(TagName.TVSHOW);
		ArrayList<TvshowObject> listTvshow = new ArrayList<TvshowObject>();
		for (int i = 0; i < jsonArraySong.length(); i++) {
			TvshowObject tvshow = new TvshowObject();
			JSONObject videoJson = jsonArraySong.getJSONObject(i);
			tvshow.setTXNAME(videoJson.getString(TagName.TXNAME));
			tvshow.setSEO_NAME(videoJson.getString(TagName.SEO_NAME));
			tvshow.setCATE_ID(videoJson.getString(TagName.CATE_ID));
			tvshow.setCATE_CODE(videoJson.getString(TagName.CATE_CODE));
			tvshow.setAVATAR(videoJson.getString(TagName.AVATAR));
			tvshow.setRN(videoJson.getString(TagName.RN));
			listTvshow.add(tvshow);
			TagName.showLogError("TVSHOW", "getTXNAME: " + tvshow.getTXNAME());
			TagName.showLogError("TVSHOW", "getCATE_CODE: " + tvshow.getCATE_CODE());
		}
		return listTvshow;
	}

	public static ArrayList<SongObject> readTvshow_listSong(String json) throws JSONException {
		JSONObject jObjData = readBodydata(json);
		JSONArray jsonArraySong = jObjData.getJSONArray(TagName.KEY_TVSHOW);
		return readlistSongs(jsonArraySong);
	}

	public static ArrayList<PlaylistObject> listPlaylist(String json) throws JSONException {
		JSONObject jObjData = readBodydata(json);
		JSONArray jsonArraySong = jObjData.getJSONArray(TagName.KEY_PLAYLIST);
		ArrayList<PlaylistObject> listmenu = new ArrayList<PlaylistObject>();
		for (int i = 0; i < jsonArraySong.length(); i++) {
			PlaylistObject song = new PlaylistObject();
			JSONObject songObj = jsonArraySong.getJSONObject(i);
			song.setALBUM_ID(songObj.getString(TagName.ALBUM_ID));
			song.setSEO_NAME(songObj.getString(TagName.SEO_NAME));
			song.setTXNAME(songObj.getString(TagName.TXNAME));
			song.setAVATAR(songObj.getString(TagName.AVATAR));
			song.setSHORTDESC(songObj.getString(TagName.SHORTDESC));
			song.setCREATE_DATE(songObj.getString(TagName.CREATE_DATE));
			song.setTOTAL_SONG(songObj.getString(TagName.TOTAL_SONG));
			song.setRN(songObj.getString(TagName.RN));
			// TagName.showLogError("PlaylistObject",
			// "_______________________________________");
			// TagName.showLogError("PlaylistObject", "ALBUM_ID" +
			// song.getALBUM_ID());
			// TagName.showLogError("PlaylistObject", "SEO_NAME" +
			// song.getSEO_NAME());
			// TagName.showLogError("PlaylistObject", "TXNAME" +
			// song.getTXNAME());
			// TagName.showLogError("PlaylistObject", "AVATAR" +
			// song.getAVATAR());
			// TagName.showLogError("PlaylistObject", "SHORTDESC" +
			// song.getSHORTDESC());
			// TagName.showLogError("PlaylistObject", "CREATE_DATE" +
			// song.getCREATE_DATE());
			// TagName.showLogError("PlaylistObject", "TOTAL_SONG" +
			// song.getTOTAL_SONG());
			// TagName.showLogError("PlaylistObject", "RN" + song.getRN());
			listmenu.add(song);
		}
		return listmenu;
	}

	public static ArrayList<SongObject> PlaylistDetails(String json) throws JSONException {
		JSONObject jObjData = readBodydata(json);
		JSONArray jsonArraySong = jObjData.getJSONArray(TagName.KEY_PLAYLIST);
		return readlistSongs(jsonArraySong);
	}

	public static ArrayList<CommentObject> listComment(String json) throws JSONException {
		JSONObject jObjData = readBodydata(json);
		JSONArray jsonArraySong = jObjData.getJSONArray(TagName.KEY_COMMENT);
		ArrayList<CommentObject> listmenu = new ArrayList<CommentObject>();
		for (int i = 0; i < jsonArraySong.length(); i++) {
			CommentObject song = new CommentObject();
			JSONObject songObj = jsonArraySong.getJSONObject(i);
			song.setAUTO_ID(songObj.getString(TagName.AUTO_ID));
			song.setOBJECT_ID(songObj.getString(TagName.OBJECT_ID));
			song.setTITLE(songObj.getString(TagName.TITLE));
			song.setAVATAR(songObj.getString(TagName.AVATAR));
			song.setTXDES(songObj.getString(TagName.TXDES));
			song.setCREATEBY(songObj.getString(TagName.CREATEBY));
			song.setCREATE_DATE(songObj.getString(TagName.CREATE_DATE));
			song.setCREATE_DATE(songObj.getString(TagName.CREATE_DATE));
			song.setRN(songObj.getString(TagName.RN));
			// TagName.showLogError("CommentObject",
			// "_______________________________________");
			// TagName.showLogError("CommentObject", "AUTO_ID" +
			// song.getAUTO_ID());
			// TagName.showLogError("CommentObject", "OBJECT_ID" +
			// song.getOBJECT_ID());
			// TagName.showLogError("CommentObject", "TITLE" + song.getTITLE());
			// TagName.showLogError("CommentObject", "AVATAR" +
			// song.getAVATAR());
			// TagName.showLogError("CommentObject", "TXDES" + song.getTXDES());
			// TagName.showLogError("CommentObject", "CREATEBY" +
			// song.getCREATEBY());
			// TagName.showLogError("CommentObject", "CREATE_DATE" +
			// song.getCREATE_DATE());
			// TagName.showLogError("CommentObject", "RN" + song.getRN());
			listmenu.add(song);
		}
		return listmenu;
	}

	public static ArrayList<SongObject> searchSong(String json) throws JSONException {
		JSONObject jObjData = readBodydata(json);
		JSONArray jsonArraySong = jObjData.getJSONArray(TagName.KEY_SONG);
		ArrayList<SongObject> listmenu = new ArrayList<SongObject>();
		for (int i = 0; i < jsonArraySong.length(); i++) {
			SongObject song = new SongObject();
			JSONObject songObj = jsonArraySong.getJSONObject(i);
			song.setSONG_ID(songObj.getString(TagName.SONG_ID));
			song.setTXNAME(songObj.getString(TagName.TXNAME));
			song.setFormNet(true);
			listmenu.add(song);
		}
		return listmenu;
	}

	public static ArrayList<SongObject> searchVideo(String json) throws JSONException {
		JSONObject jObjData = readBodydata(json);
		JSONArray jsonArraySong = jObjData.getJSONArray(TagName.KEY_VIDEO);
		ArrayList<SongObject> listmenu = new ArrayList<SongObject>();
		for (int i = 0; i < jsonArraySong.length(); i++) {
			SongObject song = new SongObject();
			JSONObject songObj = jsonArraySong.getJSONObject(i);
			song.setSONG_ID(songObj.getString(TagName.SONG_ID));
			song.setTXNAME(songObj.getString(TagName.TXNAME));
			song.setFormNet(true);
			listmenu.add(song);
		}
		return listmenu;
	}

	public static ArrayList<AlbumObject> searchAlbum(String json) throws JSONException {
		JSONObject jObjData = readBodydata(json);
		JSONArray jsonArraySong = jObjData.getJSONArray(TagName.KEY_ALBUM);
		return  readListAlbums(jsonArraySong);
	}

	public static ArrayList<SingerObject> searchSinger(String json) throws JSONException {
		JSONObject jObjData = readBodydata(json);
		JSONArray jsonArraySong = jObjData.getJSONArray("CASY");
		ArrayList<SingerObject> listmenu = new ArrayList<SingerObject>();
		for (int i = 0; i < jsonArraySong.length(); i++) {
			SingerObject song = new SingerObject();
			JSONObject songObj = jsonArraySong.getJSONObject(i);
			song.setTXNAME(songObj.getString(TagName.TXNAME));
			song.setAVATAR(songObj.getString(TagName.AVATAR));
			song.setSINGER_CODE(songObj.getString(TagName.SINGER_CODE));
			song.setSINGER_ID(songObj.getString(TagName.SINGER_ID));
			listmenu.add(song);
		}
		return listmenu;
	}
 
	public static AccountObject readUserInfo(String json) throws JSONException {
		JSONObject jObjData = readBodydata(json);
		JSONArray jsonArraySong = jObjData.getJSONArray("USER");
		AccountObject accountObject=new AccountObject();
		for (int i = 0; i < jsonArraySong.length(); i++) {
			JSONObject songObj = jsonArraySong.getJSONObject(i);
			accountObject.setFULL_NAME(songObj.getString("FULL_NAME"));
			accountObject.setUSER_CODE(songObj.getString("USER_CODE"));
			accountObject.setUSER_NAME(songObj.getString("USER_NAME"));
			accountObject.setSEX(songObj.getString("SEX"));
			accountObject.setMOBILE(songObj.getString("MOBILE"));
			accountObject.setBIRTH_DAY(songObj.getString("BIRTH_DAY"));
			accountObject.setAVATAR(songObj.getString("AVATAR"));
			
//			 TagName.showLogError("AccountObject", "FULLNAME" + 	accountObject.getFULL_NAME());
//			 TagName.showLogError("AccountObject", "USER_CODE" + 	accountObject.getUSER_CODE());
//			 TagName.showLogError("AccountObject", "USER_NAME" + 	accountObject.getUSER_NAME());
//			 TagName.showLogError("AccountObject", "SEX" + 	accountObject.getSEX());
//			 TagName.showLogError("AccountObject", "MOBILE" + 	accountObject.getMOBILE());
//			 TagName.showLogError("AccountObject", "BIRTHDAY" + 	accountObject.getBIRTH_DAY());
//			 TagName.showLogError("AccountObject", "AVATAR" + 	accountObject.getAVATAR()); 
		}
		return accountObject;
	}
}
